Object-Oriented Programming Introduction
Outline

OOP Introduction

"O O It’s magic"

More than just syntax of an O-O language.

Procedural programming practice can be a hindrance.

Requires more discipline, often enforced in the language.

OOP is analysis + design + programming.

Real-world design failure

In 1625, King Gustav wanted to sail the oceans wide,

He called for a shipwright to build the vessel right.

Hybertszoon was his name but their ideas were not the same,

So the Vasa lies at the bottom of the ocean as her only fame.

Real-world O-O Example

Where’s the Power?

Programming Evolution

Goal

Goooooalllllllllll

Better software developed faster.

History

"Don’t know much about history"

Machine Code

The language of 1’s and 0’s

Very low level, hard to program in but great speed.

Assembler

"I want to know machine language". This is much different the wanting to learn machine language.

Same speed as machine code but a little easier to program in.

Procedures and Function

Procedure must be followed in order for the machine to function

Rudimentary code-reuse and distinction between the what vs. how of a problem.

Block Scoping

Crime Watch neighborhood

The idea here is to have variables only within the procedures that need them. However, when sharing is required this mechanism does not work.

Modules

Close but no cigar

Routines linked in from outside a program to do certain tasks.

Achieved encapsulation of code and data but it broke down in instances where more than one structure that the module represented was needed.

Abstract Data Types

"In theory Communism works" – Homer J. Simpson

Extended modules with the ability of having more than one instance of itself.

Next Step O-O

From C to O-O

O-O comes from real-world philosophical concepts.

Sapir – Whorf Hypothesis

Who?

In linguistics there is a hypothesis that the language in which an idea or thought is expressed colors the nature of the thought.

Sapir and Whorf went further, and claimed that there were thoughts one could have in one language that could not ever occur, could not even be explained, to somebody thinking in a different language.

Medium is the Message

It’s called marketing

The medium is the message states that the means of communications has a greater influence on people than the information itself.

Link this with Sapir-Whorf.

Power of the Metaphor

The pen may be mightier than the sword but at any single instance the sword has a definite advantage.

Using real-world concepts to solve a program that maps into a programming style and language.

Church’s Conjecture

No, this is NOT some liberal theology

Opposite of Sapir – Whorf

The real-world is "object oriented". Thinking and programming object-oriented make the problem solving job easier.

Link this with the power of the metaphor.

Complexity and Interaction

People have always tried to use computers to solve problems that were just a little more difficult than they knew how to solve.

The problem is not the algorithm or even that projects are large it is because of the numerous interactions.

O-O helps to manage this, however programming is still difficult because we are trying to do more in the software.

O-O is a new system of organizing code.

Match Problem Domain with Problem Solving Style

A match made in heaven. Probably Not.

It is the best mainstream solution at this time.

Imperative vs. Object-Oriented

Paradigm – NOT 20 cents (a pair of dimes). It is a model.

Imperative

To Do

"Pigeon-hole" computing. Doesn’t map to real-world easily.

Fails because data is separate from functions, data is often global, and access to the data is uncontrolled and unpredictable. Testing and debugging is in turn difficult.

Object-Oriented

Indicative: To Be

Recursive design

Succeeds because code and data combined, access to data is controlled and predictable, and it maps more closely to the real world.

Object-Oriented Foundations

Don’t build your house on sinking sand

A PIE

Abstraction

Polymorphism

Inheritance

Encapsulation

Object-Oriented Concepts

A whole slew of new words and definitions

Objects

What is an object?

Contains methods and attributes

Communicates with messages

Basic element of code organization

Each instance of an object is unique

Has a life-cycle: birth, life and death

Classes

All objects have class

Class in an object definition

The terms object and class are used differently depending on the context, thus confusion.

Instances

An incarnation

Refers to an object. Most likely implemented as a "pointer" – a variable containing an address of where an specific instance of an object is located at.

Attributes

What are you like?

Traits, information, returns a value doesn’t perform program logic.

Methods

What can you do?

Perform program logic.

Messages

What do you communicate?

Like a function call.

Interface

How do you communicate?

Public method signatures

Someone using your object will program to the interface so make it long-lasting.

Abstraction

You can’t use your senses to understand a thought. Therefore, is a thought real?

Hide the details so as to hide complexity so that you can deal with a topic at a particular level.

Encapsulation

To enclose

Data and logic together.

Overloading and Overriding

Overloading – similar method call, similar meaning

Overriding – same method call, different meaning

Polymorphism

Many Meanings

Overloading is the writing of multiple functions with the same name.

Polymorphism goes further in that you can write one function to operate of many different object types.

Double Dispatch

 

Inheritance

Passing on the genes

"Is-A" relationship

Organization technique. General to specific

Composition

No, this is NOT English 101

"Has-A" relationship

Aggregation - Whole-part from the perspective of the whole

Link – Peer-to-peer

Association – parts that make up a whole

Framework

With some art you can only say, "Oh, what a lovely frame"

The inverse of a code library

OOP Recap

Kay’s description of Object-Oriented programming

Elements of OOP – Objects

Everything is an object

Elements of OOP – Messages

Objects perform computation by making requests of each other through the passing of messages

Elements of OOP – Receivers

It is better to give than to receive

Binding time

Elements of OOP – Recursive Design

Every object has it's own memory, which consists of other objects

Non-interference

Elements of OOP – Classes

Every object is an instance of a class. A class groups similar objects.

The class is the repository for behavior associated with an object.

Elements of OOP – Inheritance

Classes are organized into a singly-rooted tree structure, called an inheritance hierarchy

Elements of OOP – Overload

Overloading these circuits is good

O-O Design Why start with design?

Can’t we just start coding?

O-O System Design

All good systems have a design

Whatever methodology is employed should be one that is usable and actually used.

O-O Object Design

How would you design an object?

Development Process

Code, run, debug, repeat

Tools

Using the right tool for the jobs works so much better